<?

function GetConnection()
{
	//global $password;
	$conn = new mysqli('localhost', 'plotkinm', 'FaceBooK', 'plotkinm_db');
	return $conn;
}

$conn=GetConnection();

	if(!$conn) {
		echo 'ERROR: Could not connect to the database.';
	} 
	else {
		
		if(isset($_POST['queryString'])) {
			$searchString = $conn->real_escape_string($_POST['queryString']);
			
			if(strlen($searchString) >0) {
				$query = $conn->query("SELECT city, state, zip FROM US_Zip_Codes WHERE city LIKE '$searchString%' OR state LIKE '$searchString%' OR zip LIKE '$searchString%' LIMIT 10");
				if($query) {
					//Loop through results
					while ($result = $query ->fetch_object()) {
         				echo '<li onClick="fill(\''.$result->city.'\');">'.$result->city.'</li>';
						echo '<li onClick="fill(\''.$result->state.'\');">'.$result->state.'</li>';
						echo '<li onClick="fill(\''.$result->zip.'\');">'.$result->zip.'</li>';
         			}
				} 
				else {
					echo 'ERROR: There was a problem with the query.';
				}
			}
		}
	}
	
?>